<?php include "include/function_library.php"; ?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php include "html/header.html"; ?>

</head>
<body class="tcuk home">

	<div id="wp">
	
		<?php  include "html/menu.html"; ?>
		
		<!-- CONTENT STARTS-->
		<div id="ct"> 	
			
			<?php 
			/* LOGIN UP FORM PHP PART */
			if(post("nm_submit")) {
				$nm_email		= post("nm_email");
				$nm_password 	= post("nm_password");

				if($nm_email == "") {
					echo "<div class='alert error'>Error! Enter your email please!</div>";
				} else if($nm_password == "") {
					echo "<div class='alert error'>Error! Enter your password please!</div>";
				} else {
					$query = "SELECT * FROM user WHERE email='$nm_email' AND password='$nm_password'";
					$result = sql_query($query);
					
					$tuple = mysql_fetch_assoc($result);
					
					if($tuple["id"]) {
						$_SESSION["id"] = $tuple["id"];
						$_SESSION["name"] = $tuple["name"];
						$_SESSION["surname"] = $tuple["surname"];
						$_SESSION["email"] = $tuple["email"];
						$_SESSION["phone"] = $tuple["phone"];
						$_SESSION["sex"] = $tuple["sex"];
						$_SESSION["birthdate"] = $tuple["birthdate"];
						$_SESSION["is_customer"] = is_customer();
						
						redirect("index.php?login=1");
					} else {
						$_SESSION = array();
						echo "<div class='alert error'>Error! Email or Password is wrong! Try again!</div>";
					}
				}
			}
			?>
			<!-- LOGIN UP FORM HTML PART -->
			<form action="<?php echo curPageURL(); ?>" method="post" style="border: solid #666666; margin-top:20px; margin-left:250px; width:470px;">
			<ul id="signup_form" style="width: 50%; margin-left: auto; margin-right: auto; margin-top: 30px; list-style: none;">
				<li style="border: none;">
					<label>Email </label>
					<input type="text" id="nm_email" name="nm_email" value="" placeholder="Your Email.." style="width: 250px;"/>
				</li>
				<li>
					<label>Password </label>
					<input type="password" id="nm_password" name="nm_password" value="" placeholder="Your Password.." style="width: 250px;"/>
				</li>
				<li>
					<input type="submit" id="nm_submit" name="nm_submit" value="Login" style="width: 90px; height:30px; margin-left: 80px;"/>
				</li>
			</ul>
			</form>
		
		</div> 	
		<!-- CONTENT ENDS-->		
		
		<?php include "html/footer.html"; ?>
		
	</div>
	
</body>
</html>